package qianfeng.com.meijiadaka.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;


import qianfeng.com.meijiadaka.OneActivity;
import qianfeng.com.meijiadaka.R;
import qianfeng.com.meijiadaka.bean.AllBean;


/**
 * Created by yanshihao on 2017/2/9.
 */

public class AllAdapter extends RecyclerView.Adapter<AllAdapter.ViewHolder> {
    private Context mContext;
    private List<AllBean.ResultBean> mList;
    private RecyclerView mRecyclerView;

    public AllAdapter(Context context, List<AllBean.ResultBean> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public AllAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.home_listview,parent,false);
        AllAdapter.ViewHolder vh=new AllAdapter.ViewHolder(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = mRecyclerView.getChildAdapterPosition(v);
                Intent intent = new Intent(mContext, OneActivity.class);
                intent.putExtra("id",mList.get(position));
                mContext.startActivity(intent);
            }
        });
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv.setText(mList.get(position).getStyleName());
        Glide.with(mContext).load(mList.get(position).getStyleIcon()).into(holder.iv);
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        mRecyclerView=recyclerView;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        ImageView iv;
        TextView tv;
        public ViewHolder(View itemView) {
            super(itemView);
            iv=(ImageView)itemView.findViewById(R.id.iv1);
            tv=(TextView)itemView.findViewById(R.id.tv1);
        }
    }
}

